
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>在 微服务的架构中如何实现服务之间的负载均衡？ - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>在 微服务的架构中如何实现服务之间的负载均衡？ - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">在 Spring Cloud 中，文档提到了哪几种实现负载均衡的方式？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">文档中提到了四种主要的负载均衡实现方式：Ribbon、Feign、Spring Cloud LoadBalancer 以及 API 网关（如 Zuul/Gateway）。</div>
          </div>
          <div class="card-source">来源: 文档开篇第一段</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">如何为一个 `RestTemplate` 启用 Ribbon 的客户端负载均衡功能？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">通过在创建 `RestTemplate` 的 Bean 方法上添加 `@LoadBalanced` 注解。这样，当使用这个 `RestTemplate` 调用服务时，Ribbon 会自动从服务实例列表中选择一个实例进行请求。</div>
          </div>
          <div class="card-source">来源: 1. Ribbon</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">Feign 是如何实现负载均衡的？它与 Ribbon 是什么关系？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Feign 是一个声明式的 HTTP 客户端，它内部集成了 Ribbon。当通过 Feign 客户端接口发起服务调用时，它会自动使用其内建的 Ribbon 功能来实现客户端负载均衡。</div>
          </div>
          <div class="card-source">来源: 2. Feign</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">Spring Cloud LoadBalancer 是什么？相比于 Ribbon，它在 Spring Cloud 生态中的定位是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Spring Cloud LoadBalancer 是一个提供负载均衡功能的库。它是 Spring Cloud 2.x 及以后版本推荐使用的负载均衡工具，可以用来替代 Ribbon。</div>
          </div>
          <div class="card-source">来源: 3. Spring Cloud LoadBalancer</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">模式</div>
          <div class="card-question">Zuul 和 Spring Cloud Gateway 在哪个层面实现负载均衡？使用这种方式有什么优点？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">模式</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Zuul 和 Spring Cloud Gateway 是在 API 网关层实现负载均衡。其优点是可以在网关层集中管理路由、负载均衡、熔断等功能，并能对外提供统一的 API 接口。</div>
          </div>
          <div class="card-source">来源: 4. Zuul and Gateway</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在使用 Spring Cloud Gateway 时，如何配置路由规则以实现对服务的负载均衡？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">在配置文件（如 application.yml）中，通过设置路由的 `uri` 属性为 `lb://service-name` 的形式来配置。其中 `lb` 协议前缀表示启用负载均衡，`service-name` 是目标服务的名称。</div>
          </div>
          <div class="card-source">来源: 4. Zuul and Gateway</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
